import pagination from '@/views/pagination'  //分页组件
import dialogForm from './edit'
import agentHttp from '@/utils/agentHttp.js'//引用JS
import {debounce,setEndDateTime} from '@/utils/index.js'
export default {
  name: 'logisticsInfo',//组件名称
  components:{dialogForm,pagination},//引用的组件
  created(){//初始化
    this.seachData();
  },
  data() {//初始化数据
    let that = this;
  	return {
      //表格字段
      tableData:{
         logisticsFollowStatus:''
      },
      //搜索字段
  		searchForm:{
  			carOrder:{orderNumber:"",carBrand:"",carName:"",logisticsFollowStatus:""},
  			dealer:{name:""},
  			logisticsCompany:{id:""},
        startDate:"",
        endDate:"",
        status:""
  		},
      //发送给弹窗的数据
      dialogSendData:{
        isAdd:true,                //是否为编辑或者新增  true是   false否
        dialogFormVisible:false,   //弹窗是否显示        true是   false否
        id:""          //请求参数            自定义 例如index或者id
      },
      //label宽度
      formLabelWidth:'120px',
      statusMap:'',
      followStatusMap:'',
      logisticsCompanyList:'',
      carOrderStatusMap:'',
      startDateOpt: {
             disabledDate(time) {
                return time.getTime() > Date.now() 
             }
          },
      endDateOpt:{
        disabledDate:(time)=>{
                return  time.getTime()< new Date(this.searchForm.startDate).getTime();
             }
      },
      resetFormStatus:false
  	}
  },
  methods: {//所有方法
    //列表查询
    seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        params.endDate = setEndDateTime(params.endDate);
        agentHttp.postJson('adminApi/admin/logistics_info/list?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
          if (data.success) {
            this.tableData = data.data.tableData;
            this.statusMap = data.data.statusMap;
            this.logisticsCompanyList = data.data.logisticsCompanyList;
            this.carOrderStatusMap = data.data.carOrderStatusMap;
            this.followStatusMap = data.data.followStatusMap; 
          }
        })
      }
    },
    //延迟搜索
    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(),1000)
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //查看
    handleSee(index, row){
      this.dialogSendData.isAdd=false;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    },
    //编辑
    handleEdit(index, row){
      this.dialogSendData.isAdd=true;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    }   
  }
}
